﻿using MaterialDesignColors;
using MaterialDesignColors.ColorManipulation;
using MaterialDesignThemes.Wpf;
using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Media;

namespace DailyApp.WPF.ViewModels
{
    class PersonalUCViewModel: BindableBase
    {
        #region 设置主题背景
        private bool _isDarkTheme;
        public bool IsDarkTheme
        {
            get => _isDarkTheme;
            set
            {
                if (SetProperty(ref _isDarkTheme, value))
                {
                    ModifyTheme(theme => theme.SetBaseTheme(value ? BaseTheme.Dark : BaseTheme.Light));//Theme
                }
            }
        }
        //修改主题
        private static void ModifyTheme(Action<Theme> modificationAction)
        {
            var paletteHelper = new PaletteHelper();
            Theme theme = paletteHelper.GetTheme();//ITheme

            modificationAction?.Invoke(theme);

            paletteHelper.SetTheme(theme);
        }

        #endregion

        public PersonalUCViewModel()
        {
            ChangeHueCommand = new DelegateCommand<object>(ChangeHue);
        }

        #region 顶部背景颜色
        private readonly PaletteHelper paletteHelper = new PaletteHelper();//调色板帮手
        public DelegateCommand<object> ChangeHueCommand { get; }

        public IEnumerable<ISwatch> Swatches { get; } = SwatchHelper.Swatches;

        private void ChangeHue(object? obj)
        {
            //var hue = (Color)obj!;

            //SelectedColor = hue;
            //if (ActiveScheme == ColorScheme.Primary)
            //{
            //    _paletteHelper.ChangePrimaryColor(hue);
            //    _primaryColor = hue;
            //    _primaryForegroundColor = _paletteHelper.GetTheme().PrimaryMid.GetForegroundColor();
            //}
           
            Theme theme = paletteHelper.GetTheme();//Theme ->ITheme接口类型

            var color = (Color)obj!;
            theme.PrimaryLight = new ColorPair(color.Lighten());
            theme.PrimaryMid = new ColorPair(color);
            theme.PrimaryDark = new ColorPair(color.Darken());

            paletteHelper.SetTheme(theme);
        }
        #endregion


    }
}
